home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / TASEXAM6.ARJ / PEAKS4.TAS < prev    next >
Text File  |  1991-05-25  |  10KB  |  239 lines

  1. {
  2.       * CAUTION YOU MUST HAVE THE SP-500 IN YOUR DATABASE FOR THE
  3.         INDEX TO WORK.  ALSO YOU MAY NEED TO INCREASE YOUR SYMBOL
  4.         SIZE IN THE CONFIGURE SCREEN OF TAS.*
  5.       This script tries to determine cycle length by looking at the
  6.       average peaks and troughs of a zigzag indicator.  The last five
  7.       peaks and troughs are averaged to try to determine the next
  8.       peak and trough.  A second function of this script is to determine
  9.       trend strength by looking at a cycle average of price and volume.
  10.       The stocks are also compared to the SP-500 and then a percent
  11.       number is given to how over bought or over sold they are.
  12.       All indicators are based on the time period found in the zigzag
  13.       function.  Cycle studies are usually given a 15% bandwidth so
  14.       keep this in mind. Also this looks at short cycles which may
  15.       be under the influence of longer cycles.
  16.       May 1991. Jerry Green
  17. }
  18. #max_quotes 120
  19. #index 'SP-500'
  20. #output_file 'Peaks.LST'
  21. rs_trgr : number;                { define some numbers }
  22. so_trgr : number;
  23. rt_trgr : number;
  24. days_back : number;
  25. rs_c : array;                     { define some arrays }
  26. so_c : array;
  27. rt_c : array;
  28. rs_sort : array;
  29. Z : ARRAY;
  30. if first_ticker then
  31. begin
  32. writeln(' CYCLE, TREND AND VALUE STUDY BASED ON AVERAGE ZIGZAG CYCLES');
  33. writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
  34. writeln(' ');
  35. end;
  36. if quote_count <= 100 then
  37. return;             {skip short data file}
  38. begin
  39. pk_5 = 0;                    {make sure we are clear from}
  40. tr_5 = 0;                    {one ticker to the next}
  41. pk_4 = 0;                    {varibles to store peak and }
  42. tr_4 = 0;                    {trough differences }
  43. pk_3 = 0;
  44. tr_3 = 0;
  45. pk_2 = 0;
  46. tr_2 = 0;
  47. pk_1 = 0;
  48. tr_1 = 0;
  49. pks_t = 0;                   {peaks to troughs}
  50. trs_p = 0;                   {troughs to peaks}
  51. pks_ta = 0;                  {average of pks_t}
  52. trs_pa = 0;                  {average of trs_p}
  53. nx_pk = 0;                   {next peak}
  54. nx_tr = 0;                   {next trough}
  55. s_t = 0;                     {rate of change for ticker}
  56. s_p = 0;                     {rate of change for index}
  57. rel_str = 0;                 {relative strength to index}
  58. ob_os = 0;                   {overbought oversold}
  59. rs_trgr = 0;                 {relative strength accumulator}
  60. so_trgr = 0;                 {stochastic accumulator}
  61. rt_trgr = 0;                 {rate of change accumulator}
  62. rs_sort = 0;                 {total of trgrs}
  63. pt1 = 0;                     {varibles for storing peaks}
  64. pt2 = 0;
  65. pt3 = 0;
  66. pt4 = 0;
  67. pt5 = 0;
  68. tp1 = 0;                     {varibles for storing troughs}
  69. tp2 = 0;
  70. tp3 = 0;
  71. tp4 = 0;
  72. tp5 = 0;
  73. {-------------------ZIGZAG STUDY STARTS HERE-------------------}
  74. if C >= 100  then             {check close to determine %}
  75.      z_v = 2;                 {calculate a zigag ind }
  76. if C <= 100 then
  77.      z_v = 5;
  78. Z = ZIG(c,z_v,'%');
  79. pt5 = peak(Z,5);              {get peaks back 5 waves}
  80. pt4 = peak(Z,4);
  81. pt3 = peak(Z,3);
  82. pt2 = peak(Z,2);
  83. pt1 = peak(Z,1);
  84. tp5 = trough(Z,5);            {get troughs back 5 waves}
  85. tp4 = trough(Z,4);
  86. tp3 = trough(Z,3);
  87. tp2 = trough(Z,2);
  88. tp1 = trough(Z,1);
  89. if pt1 >= 0 then          {don't let a peak = 0}
  90.   pt1 = pt2;
  91. if tp1 >= 0 then          {don't let a trough = 0}
  92.   tp1 = tp2;
  93. if pt5 < tp5 then         {check out the waves dude}
  94. goto backpeak             {make sure you catch the first one}
  95. else
  96. goto backtrough;
  97. :backpeak
  98. pk_5 = pt5 - tp5;
  99. tr_5 = tp5 - pt4;         {now the cycle analysis starts}
  100. pk_4 = pt4 - tp4;         {we are finding the days from }
  101. tr_4 = tp4 - pt3;         {peak to trough, trough to peak}
  102. pk_3 = pt3 - tp3;         {the zigzag is used because it}
  103. tr_3 = tp3 - pt2;         {gives the best veiw of the past}
  104. pk_2 = pt2 - tp2;         {by looking ahead in the data }
  105. tr_2 = tp2 - pt1;         {this can tell us the cycles }
  106. pk_1 = pt1 - tp1;
  107. tr_1 = tp1;
  108. goto cycle;
  109. :backtrough
  110. tr_5 = tp5 - pt5;         {two models are used to take}
  111. pk_5 = pt5 - tp4;         {into account the difference }
  112. tr_4 = tp4 - pt4;         {in first peak or first trough}
  113. pk_4 = pt4 - tp3;
  114. tr_3 = tp3 - pt3;
  115. pk_3 = pt3 - tp2;
  116. tr_2 = tp2 - pt2;
  117. pk_2 = pt2 - tp1;
  118. tr_1 = tp1 - pt1;
  119. pk_1 = pt1;
  120. goto cycle;
  121. :cycle
  122. pks_t = pk_5+pk_4+pk_3+pk_2+pk_1;   {add peaks to troughs}
  123. trs_p = tr_5+tr_4+tr_3+tr_2+tr_1;   {add troughs to peaks}
  124. pks_ta = (0-(pks_t/5));             {determine peaks and change to +}
  125. trs_pa = (0-(trs_p/5));             {do same for troughs            }
  126.   nx_tr = pks_ta+pk_1;    {peak and trough functions return negative}
  127.   nx_pk = trs_pa+tr_1;    {numbers so we add last to avg to find next}
  128. avg_c = (pks_ta + trs_pa)/2;     {calculate and average cycle }
  129. days_back = avg_c;               {days to go back in rank section}
  130. avg_c = int(avg_c);
  131. {---------------ZIGZAG STOPS AND OB-OS STARTS------------------}
  132. rs_c = rsi(avg_c);                    { calculate an RSI }
  133. so_c = stoch(int(avg_c/2),3);         { STOCHASTIC }
  134. rt_c = roc(c,avg_c,'%');              { RATE OF CHANGE }
  135. bb_top = bbandt(avg_c,2);             { BOLLENGER TOP BAND }
  136. bb_bot = bbandb(avg_c,2);             { BOLLINGER BOTTOM BAND }
  137. :loop1
  138. if rs_c[days_back] > 70 then       { a loop to accumulate counts for }
  139.       rs_trgr = rs_trgr + 1;       { indicator performance }
  140. if rs_c[days_back] < 30 then
  141.       rs_trgr = rs_trgr - 1;
  142. if so_c[days_back] > 80 then
  143.       so_trgr = so_trgr + 1;
  144. if so_c[days_back] < 20 then
  145.       so_trgr = so_trgr - 1;
  146. if c > 100 then
  147.    n = 2 and nn = -2                { if ticker is > 100 change ROC }
  148. else                                { to look at 2% change, if cheaper }
  149.    n = 7 and nn = -7;               { use 7% a number William Oneil likes}
  150. if rt_c[days_back] > n then
  151.       rt_trgr = rt_trgr + 1;
  152. if rt_c[days_back] < nn then
  153.       rt_trgr = rt_trgr - 1;
  154. days_back = days_back + 1;          { increase counter by 1 until today }
  155. if days_back >= 1 then              { is reached. today is 0  }
  156. goto done
  157. else
  158. goto loop1;
  159. :done
  160. rs_sort = rs_trgr + so_trgr + rt_trgr;    { add them for final rank}
  161. {------------OB-OS STOPS AND TREND STUDY STARTS HERE--------}
  162. AVG_VOL = MOV(V,avg_c/2,'E'); {moving average of 1/2 cycle on volume}
  163. IF V < AVG_VOL THEN                       {if todays vol is less than}
  164.      VS_TRGR = - 1;                       {the avgerage VS_TRGR =-1}
  165. ELSE                                      {if greater then VS_TRGR =1}
  166.      VS_TRGR = 1;
  167. AVG_CLSE := MOV(C,avg_c,'E');             {use same logic for CS_TRGR}
  168. IF C < AVG_CLSE THEN
  169.      CS_TRGR = -1;
  170. ELSE
  171.      CS_TRGR = 1;
  172. IF CS_TRGR = 1 AND VS_TRGR = 1 THEN       {this is typical thinking of}
  173. begin                                     {how vol and price interact }
  174.      trend = 'STRONG UP  -> HOLD LONG';    { refer to Jack}
  175.      su_trnd = su_trnd + 1;               {Schwager's book A COMPLETE  }
  176. end;                                      {GUIDE TO THE FUTURES MARKETS}
  177. IF CS_TRGR = 1 AND VS_TRGR = -1 THEN      {pages 367_371.}
  178. begin
  179.      trend = 'WEAK UP  -> SELL ???'; {we also keep track of the}
  180.      wu_trnd = wu_trnd + 1;               {trends for a summary}
  181. end;
  182. IF CS_TRGR = -1 AND VS_TRGR = -1 THEN
  183. begin
  184.      trend = 'STRONG DN  -> HOLD SHORT';
  185.      sd_trnd = sd_trnd + 1;
  186. end;
  187. IF CS_TRGR = -1 AND VS_TRGR = 1 THEN
  188. begin
  189.      trend = 'WEAK DN  -> BUY ???';
  190.      wd_trnd = wd_trnd + 1;
  191. end;
  192. IF AVG_VOL = 0 THEN
  193.      trend = 'TICKER W/NO VOL';
  194. {             -  added by Jim Camenos -
  195.       This is a filter to screen 10 percent possible
  196.       gains.  To activate add an end quote bracket here ->
  197. if (((c[pt1]-c)/c)*100) < 10 then
  198. return;
  199. <-    and put a start quote bracket in front of this arrow
  200.            - end the part added by Jim - }
  201. av_cyc = int(0 - avg_c);
  202. s_p = ((index-index[av_cyc])/index[av_cyc])+1;
  203. s_t = ((c-c[av_cyc])/c[av_cyc])+1;
  204. rel_str = 50 + (100*((s_t/s_p)-1));
  205. {    --  To filter SP-500 strength add this filter ->
  206. if rel_str < 50 then
  207. return;
  208. <- this gives you only those acting better than the S&P -- }
  209. {------------------TREND STUDY STOPS HERE------------}
  210. writeln(ticker,' ','SHORT TERM TIMING AT',' ',avg_c,' ','day cycle',
  211. ' ',z_v,' ','% ZIGZAG');
  212. writeln('           ','Average peak to trough',pks_ta,' ','days');
  213. writeln('           ','Average trough to peak',trs_pa,' ','days');
  214. writeln('           ','Next peak  ',' ',nx_pk,' ','Last peak  ',' ',pt1);
  215. writeln('           ','Next trough',' ',nx_tr,' ','Last trough',' ',tp1);
  216. writeln('           ','Close today','  ','Last peak','  ','Last trough');
  217. writeln('           ',c,'     ',c[pt1],'    ',c[tp1]);
  218. writeln('           ','Possible gain',' ',((c[pt1]-c)/c)*100,' ','%');
  219. writeln('           ','Possible risk',' ',((c-c[tp1])/c)*100,' ','%');
  220. writeln('           ','Volume & price trend',' ',trend);
  221. writeln('           ',avg_c,' ','Day Relative strength',' ',rs_c);
  222. writeln('           ',int(avg_c/2),' ','Day Stochastic',' ',so_c);
  223. writeln('           ',avg_c,' ','Day Rate of Change',' ',rt_c);
  224. writeln('           ',avg_c,' ','Day Top Bollinger Band',' ',bb_top);
  225. writeln('           ',avg_c,' ','Day Bottom Bollinger Band',' ',bb_bot);
  226. writeln('           ','Relative strength to S&P. 50 is even',' ',rel_str);
  227. if rs_sort = 0 then
  228. writeln('           ','Ticker is evenly valued at this cycle!');
  229. if rs_sort <> 0 then
  230. ob_os = (rs_sort/avg_c)*100;
  231. if rs_sort < 0 then
  232. writeln('           ','Ticker is oversold by',' ',ob_os,' ','%');
  233. if rs_sort > 0 then
  234. writeln('           ','Ticker is overbought by',' ',ob_os,' ','%');
  235. writeln('------------------------------------------------------------');
  236. end;
  237. if last_ticker then
  238. end;
  239.